// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';

/** 用户登录 POST /login */
export async function userLoginUsingPost(
  body: API.UserLoginRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseUserLoginVo_>('/v1/login', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 获取图片验证码 POST /captcha/get */
export async function loginCaptchaUsingPost(options?: { [key: string]: any },) {
  return request<API.BaseResponseCaptchaVo_>('/v1/captcha/get', {
    method: 'POST',
    ...(options || {}),
  });
}

/** 校验用户滑动位置 POST /captcha/check */
export async function loginCaptchaCheckPost(
  body: API.UserCaptchaRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseCaptchaUserVo_>('/v1/captcha/check', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 忘记密码 POST /v1/forgetPassword */
export async function forgetPasswordPost(
  body: API.UserForgetRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseUserUpdateVo_>('/v1/forgetPassword', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 用户注册 POST /register */
export async function userRegisterUsingPost(
  body: API.UserRegisterRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseUserRegisterVo_>('/v1/register', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}


/** 获取邮箱验证码 POST /sendEmailCode */
export async function userRegisterEmailPost(
  body: API.UserEmailRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseCaptchaUserVo_>('/v1/sendEmailCode', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 更新头像 POST /uploadPicture */
export async function updateMyUserAvatarPost(
  body: FormData,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseAvatarVo_>('/v1/uploadPicture', {
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data;',
    },
    data: body,
    ...(options || {}),
  });
}

/** 修改个人信息 POST /updateUserInfo */
export async function updateMyUserUsingPost(
  body: API.UserUpdateMyRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseUserUpdateVo_>('/v1/updateUserInfo', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 修改密码 POST /updateUserPassword */
export async function updateMyUserPswPost(
  body: API.UserUpdatePswRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponsePswUserVo_>('/v1/updateUserPassword', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 刷新token POST /v1/refreshToken */
export async function refreshTokenPost(
  body: API.refreshTokenRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseString_>('/v1/refreshToken', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}


/** 分页获取用户列表（仅管理员） POST /admin/getUserList */
export async function listUserByPageUsingPost(
  body: API.UserQueryRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponsePageUser_>('/admin/getUserList', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 更新用户（仅管理员） PUT /admin/editUser */
export async function updateUserUsingPost(
  body: API.UserUpdateRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseUserUpdateVo_>('/admin/editUser', {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 删除用户（仅管理员） POST /admin/deleteUsers */
export async function deleteUserUsingPost(
  body: API.UserDeleteRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseBoolean_>('/admin/deleteUsers', {
    method: 'DELETE',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

// /** 导出用户数据（仅管理员） /admin/exportExcel */
export async function exportExcelUserUsingPost(
  body:API.exportExcelRequest,
  options?: { [key: string]: any },
) {
  const response = await request('/admin/exportExcel', {
    method: 'POST',
    headers: {
    'Content-Type': 'application/json;'
  },
  responseType: "blob",
  data: body,
  ...(options || {}),
  });
  // 转换Blob对象为可下载的URL
  const url = window.URL.createObjectURL(response);
  // 创建一个下载链接
  const downloadLink = document.createElement('a');
  downloadLink.href = url;
  downloadLink.download = 'users.xlsx'; // 设置下载文件的名称
  // 触发下载
  document.body.appendChild(downloadLink);
  downloadLink.click();
  // 下载完成后清理资源
  document.body.removeChild(downloadLink);
  window.URL.revokeObjectURL(url);
}


/** 导出用户数据（仅管理员） /admin/exportExcel */
// export async function exportExcelUserUsingPost(
//   body:API.exportExcelRequest,
//   options?: { [key: string]: any },
// ) {
//   const response = await request('/admin/exportExcel', {
//     method: 'POST',
//     headers: {
//     'Content-Type': 'application/json'
//   },
//   data: body,
//   responseType: "blob",
//   ...(options || {}),
//   });
//   let reader = new FileReader();
//     reader.readAsDataURL(response);
//     reader.onloadend = function() {
//     const dataUrl = reader.result;
//     const downloadLink = document.createElement('a');
//     downloadLink.download = 'users.xlsx';
//     document.body.appendChild(downloadLink);
//     downloadLink.href = dataUrl;
//     downloadLink.click();
//     document.body.removeChild(downloadLink);
//   }
// }
